Wiimote1.led1 = true Wiimote2.led1 = true Wiimote2.led4 = true Wiimote3.led2 = true Wiimote4.led2 = true Wiimote4.led4 = true Wiimote5.led3 = true Wiimote6.led3 = true Wiimote6.led4 = true //Mouse Control Script using IR //by vkapadia with much assistance from inio //vkapadia@vkapadia.com // //Calibration: //To calibrate, run this program and put the Wiimote on a flat surface face-up. //Then read the values in the debug line (next to the run button). //Change these values until the debug line reads approx. all zeros. var.xtrim1 = -1 var.ytrim1 = -25 var.ztrim1 = 2 var.xtrim2 = 3 var.ytrim2 = -30 var.ztrim2 = 2 var.xtrim3 = 2 var.ytrim3 = -27 var.ztrim3 = 2 var.xtrim4 = 2 var.ytrim4 = -30 var.ztrim4 = 2 var.coeff = 0.1 // //Options: var.deadzone = 5 //distance in pixels that you have to move the wiimote in //order for it to register movement. Creates a "dead zone" around the pointer //to make it easier to click. Higher = smoother but less accurate. //fake cursor init //cursor2.visible = true //more options to be added later //Controls: //Point Wiimote = Move Mouse //D-Pad = Arrow Keys //B-Button = Left Click //Home = Middle Click //A-Button = Right Click //Plus and Minus = Control Volume //One = Unmapped //Two = Unmapped // //If the pointer hits the edge of the screen, the Wiimote will rumble a bit. // //The LEDs attempt to emulate KITT's grill from Knight Rider //WIIMOTE 1 //***Do not edit anything below this line unless you know what you are doing.*** var.accx1 = wiimote1.RawForceX + var.xtrim1 var.accy1 = wiimote1.RawForceY + var.ytrim1 var.accz1 = wiimote1.RawForceZ + var.ztrim1 if wiimote1.dot1vis and wiimote1.dot2vis then if var.accy1 > -7 then var.orientation1 = 0 elseif var.accy1 > -45 then if var.accx1 < 0 then var.orientation1 = 3 else var.orientation1 = 1 endif else var.orientation1 = 2 endif if var.leftpoint1 = 0 then if var.orientation1 = 0 then if wiimote1.dot1x < wiimote1.dot2x then var.leftpoint1 = 1 else var.leftpoint1 = 2 endif endif if var.orientation1 = 1 then if wiimote1.dot1y > wiimote1.dot2y then var.leftpoint1 = 1 else var.leftpoint1 = 2 endif endif if var.orientation1 = 2 then if wiimote1.dot1x > wiimote1.dot2x then var.leftpoint1 = 1 else var.leftpoint1 = 2 endif endif if var.orientation1 = 3 then if wiimote1.dot1y < wiimote1.dot2y then var.leftpoint1 = 1 else var.leftpoint1 = 2 endif endif endif if var.leftpoint1 = 1 then var.fix1x1 = wiimote1.dot1x var.fix1y1 = wiimote1.dot1y var.fix2x1 = wiimote1.dot2x var.fix2y1 = wiimote1.dot2y else var.fix1x1 = wiimote1.dot2x var.fix1y1 = wiimote1.dot2y var.fix2x1 = wiimote1.dot1x var.fix2y1 = wiimote1.dot1y endif var.dx1 = var.fix2x1 - var.fix1x1 var.dy1 = var.fix2y1 - var.fix1y1 var.cx1 = (var.fix1x1+var.fix2x1)/1024.0 - 1 var.cy1 = (var.fix1y1+var.fix2y1)/1024.0 - .75 var.d1 = sqrt(var.dx1*var.dx1+var.dy1*var.dy1) var.dx1 = var.dx1 / var.d1 var.dy1 = var.dy1 / var.d1 var.ox1 = -var.dy1*var.cy1-var.dx1*var.cx1; var.oy1 = -var.dx1*var.cy1+var.dy1*var.cx1; var.ax1 = (var.ox1 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2) var.ay1 = (-var.oy1* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2) var.dx1 = var.ax1 - cursor2.posx var.dy1 = var.ay1 - cursor2.posy var.d1 = sqrt((var.dx1*var.dx1)+(var.dy1*var.dy1)) var.a1 = 180 / (200 + var.d1 * var.d1 * var.d1 * .001) if var.d1 <= var.deadzone then var.a1 = 1 //debug = var.d + " " + var.a var.finalx1 = cursor2.posx * var.a1 + var.ax1 * (1 - var.a1) var.finaly1 = cursor2.posy * var.a1 + var.ay1 * (1 - var.a1) cursor2.posx = smooth(var.finalx1,3,5) cursor2.posy = smooth(var.finaly1,3,5) else var.leftpoint1 = 0 endif var.xpos1 = var.finalx1 var.ypos1 = var.finaly1 ppjoy1.analog0 = ensuremaprange(var.xpos1,0,screen.desktopwidth* var.coeff,-1,1) ppjoy1.analog1 = ensuremaprange(var.ypos1,0,screen.desktopheight* var.coeff,-1,1) if wiimote1.B or wiimote1.A or wiimote1.Up or wiimote1.down or wiimote1.Left or wiimote1.Right == true ppjoy1.digital0 = true else ppjoy1.digital0 = false endif //WIIMOTE 2 //***Do not edit anything below this line unless you know what you are doing.*** var.accx2 = wiimote2.RawForceX + var.xtrim2 var.accy2 = wiimote2.RawForceY + var.ytrim2 var.accz2 = wiimote2.RawForceZ + var.ztrim2 if wiimote2.dot1vis and wiimote2.dot2vis then if var.accy2 > -7 then var.orientation2 = 0 elseif var.accy2 > -45 then if var.accx2 < 0 then var.orientation2 = 3 else var.orientation2 = 1 endif else var.orientation2 = 2 endif if var.leftpoint2 = 0 then if var.orientation2 = 0 then if wiimote2.dot1x < wiimote2.dot2x then var.leftpoint2 = 1 else var.leftpoint2 = 2 endif endif if var.orientation2 = 1 then if wiimote2.dot1y > wiimote2.dot2y then var.leftpoint2 = 1 else var.leftpoint2 = 2 endif endif if var.orientation2 = 2 then if wiimote2.dot1x > wiimote2.dot2x then var.leftpoint2 = 1 else var.leftpoint2 = 2 endif endif if var.orientation2 = 3 then if wiimote2.dot1y < wiimote2.dot2y then var.leftpoint2 = 1 else var.leftpoint2 = 2 endif endif endif if var.leftpoint2 = 1 then var.fix1x2 = wiimote2.dot1x var.fix1y2 = wiimote2.dot1y var.fix2x2 = wiimote2.dot2x var.fix2y2 = wiimote2.dot2y else var.fix1x2 = wiimote2.dot2x var.fix1y2 = wiimote2.dot2y var.fix2x2 = wiimote2.dot1x var.fix2y2 = wiimote2.dot1y endif var.dx2 = var.fix2x2 - var.fix1x2 var.dy2 = var.fix2y2 - var.fix1y2 var.cx2 = (var.fix1x2+var.fix2x2)/1024.0 - 1 var.cy2 = (var.fix1y2+var.fix2y2)/1024.0 - .75 var.d2 = sqrt(var.dx2*var.dx2+var.dy2*var.dy2) var.dx2 = var.dx2 / var.d2 var.dy2 = var.dy2 / var.d2 var.ox2 = -var.dy2*var.cy2-var.dx2*var.cx2; var.oy2 = -var.dx2*var.cy2+var.dy2*var.cx2; var.ax2 = (var.ox2 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2) var.ay2 = (-var.oy2* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2) var.dx2 = var.ax2 - cursor3.posx var.dy2 = var.ay2 - cursor3.posy var.d2 = sqrt((var.dx2*var.dx2)+(var.dy2*var.dy2)) var.a2 = 180 / (200 + var.d2 * var.d2 * var.d2 * .001) if var.d2 <= var.deadzone then var.a2 = 1 //debug = var.d + " " + var.a var.finalx2 = cursor3.posx * var.a2 + var.ax2 * (1 - var.a2) var.finaly2 = cursor3.posy * var.a2 + var.ay2 * (1 - var.a2) cursor3.posx = smooth(var.finalx2,3,5) cursor3.posy = smooth(var.finaly2,3,5) else var.leftpoint2 = 0 endif var.xpos2 = var.finalx2 var.ypos2 = var.finaly2 ppjoy2.analog0 = ensuremaprange(var.xpos2,0,screen.desktopwidth* var.coeff,-1,1) ppjoy2.analog1 = ensuremaprange(var.ypos2,0,screen.desktopheight* var.coeff,-1,1) if wiimote2.B or wiimote2.A or wiimote2.Up or wiimote2.down or wiimote2.Left or wiimote2.Right == true ppjoy2.digital0 = true else ppjoy2.digital0 = false endif debug = var.accx2+ " " + var.accy2+ " " + var.accz2 //WIIMOTE 3 //***Do not edit anything below this line unless you know what you are doing.*** var.accx3 = wiimote3.RawForceX + var.xtrim3 var.accy3 = wiimote3.RawForceY + var.ytrim3 var.accz3 = wiimote3.RawForceZ + var.ztrim3 if wiimote3.dot1vis and wiimote3.dot2vis then if var.accy3 > -7 then var.orientation3 = 0 elseif var.accy3 > -45 then if var.accx3 < 0 then var.orientation3 = 3 else var.orientation3 = 1 endif else var.orientation3 = 2 endif if var.leftpoint3 = 0 then if var.orientation3 = 0 then if wiimote3.dot1x < wiimote3.dot2x then var.leftpoint3 = 1 else var.leftpoint3 = 2 endif endif if var.orientation3 = 1 then if wiimote3.dot1y > wiimote3.dot2y then var.leftpoint3 = 1 else var.leftpoint3 = 2 endif endif if var.orientation3 = 2 then if wiimote3.dot1x > wiimote3.dot2x then var.leftpoint3 = 1 else var.leftpoint3 = 2 endif endif if var.orientation3 = 3 then if wiimote3.dot1y < wiimote3.dot2y then var.leftpoint3 = 1 else var.leftpoint3 = 2 endif endif endif if var.leftpoint3 = 1 then var.fix1x3 = wiimote3.dot1x var.fix1y3 = wiimote3.dot1y var.fix2x3 = wiimote3.dot2x var.fix2y3 = wiimote3.dot2y else var.fix1x3 = wiimote3.dot2x var.fix1y3 = wiimote3.dot2y var.fix2x3 = wiimote3.dot1x var.fix2y3 = wiimote3.dot1y endif var.dx3 = var.fix2x3 - var.fix1x3 var.dy3 = var.fix2y3 - var.fix1y3 var.cx3 = (var.fix1x3+var.fix2x3)/1024.0 - 1 var.cy3 = (var.fix1y3+var.fix2y3)/1024.0 - .75 var.d3 = sqrt(var.dx3*var.dx3+var.dy3*var.dy3) var.dx3 = var.dx3 / var.d3 var.dy3 = var.dy3 / var.d3 var.ox3 = -var.dy3*var.cy3-var.dx3*var.cx3; var.oy3 = -var.dx3*var.cy3+var.dy3*var.cx3; var.ax3 = (var.ox3 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2) var.ay3 = (-var.oy3* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2) var.dx3 = var.ax3 - cursor4.posx var.dy3 = var.ay3 - cursor4.posy var.d3 = sqrt((var.dx3*var.dx3)+(var.dy3*var.dy3)) var.a3 = 180 / (200 + var.d3 * var.d3 * var.d3 * .001) if var.d3 <= var.deadzone then var.a3 = 1 //debug = var.d + " " + var.a var.finalx3 = cursor4.posx * var.a3 + var.ax3 * (1 - var.a3) var.finaly3 = cursor4.posy * var.a3 + var.ay3 * (1 - var.a3) cursor4.posx = smooth(var.finalx3,3,5) cursor4.posy = smooth(var.finaly3,3,5) else var.leftpoint3 = 0 endif var.xpos3 = var.finalx3 var.ypos3 = var.finaly3 ppjoy3.analog0 = ensuremaprange(var.xpos3,0,screen.desktopwidth* var.coeff,-1,1) ppjoy3.analog1 = ensuremaprange(var.ypos3,0,screen.desktopheight* var.coeff,-1,1) if wiimote3.B or wiimote3.A or wiimote3.Up or wiimote3.down or wiimote3.Left or wiimote3.Right == true ppjoy3.digital0 = true else ppjoy3.digital0 = false endif debug = var.accx1+ " " + var.accy1+ " " + var.accz1 //WIIMOTE 3 //***Do not edit anything below this line unless you know what you are doing.*** var.accx4 = wiimote4.RawForceX + var.xtrim4 var.accy4 = wiimote4.RawForceY + var.ytrim4 var.accz4 = wiimote4.RawForceZ + var.ztrim4 if wiimote4.dot1vis and wiimote4.dot2vis then if var.accy4 > -7 then var.orientation4 = 0 elseif var.accy4 > -45 then if var.accx4 < 0 then var.orientation4 = 3 else var.orientation4 = 1 endif else var.orientation4 = 2 endif if var.leftpoint4 = 0 then if var.orientation4 = 0 then if wiimote4.dot1x < wiimote4.dot2x then var.leftpoint4 = 1 else var.leftpoint4 = 2 endif endif if var.orientation4 = 1 then if wiimote4.dot1y > wiimote4.dot2y then var.leftpoint4 = 1 else var.leftpoint4 = 2 endif endif if var.orientation4 = 2 then if wiimote4.dot1x > wiimote4.dot2x then var.leftpoint4 = 1 else var.leftpoint4 = 2 endif endif if var.orientation4 = 3 then if wiimote4.dot1y < wiimote4.dot2y then var.leftpoint4 = 1 else var.leftpoint4 = 2 endif endif endif if var.leftpoint4 = 1 then var.fix1x4 = wiimote4.dot1x var.fix1y4 = wiimote4.dot1y var.fix2x4 = wiimote4.dot2x var.fix2y4 = wiimote4.dot2y else var.fix1x4 = wiimote4.dot2x var.fix1y4 = wiimote4.dot2y var.fix2x4 = wiimote4.dot1x var.fix2y4 = wiimote4.dot1y endif var.dx4 = var.fix2x4 - var.fix1x4 var.dy4 = var.fix2y4 - var.fix1y4 var.cx4 = (var.fix1x4+var.fix2x4)/1024.0 - 1 var.cy4 = (var.fix1y4+var.fix2y4)/1024.0 - .75 var.d4 = sqrt(var.dx4*var.dx4+var.dy4*var.dy4) var.dx4 = var.dx4 / var.d4 var.dy4 = var.dy4 / var.d4 var.ox4 = -var.dy4*var.cy4-var.dx4*var.cx4; var.oy4 = -var.dx4*var.cy4+var.dy4*var.cx4; var.ax4 = (var.ox4 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2) var.ay4 = (-var.oy4* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2) var.dx4 = var.ax4 - cursor5.posx var.dy4 = var.ay4 - cursor5.posy var.d4 = sqrt((var.dx4*var.dx4)+(var.dy4*var.dy4)) var.a4 = 180 / (200 + var.d4 * var.d4 * var.d4 * .001) if var.d4 <= var.deadzone then var.a4 = 1 //debug = var.d + " " + var.a var.finalx4 = cursor5.posx * var.a4 + var.ax4 * (1 - var.a4) var.finaly4 = cursor5.posy * var.a4 + var.ay4 * (1 - var.a4) cursor5.posx = smooth(var.finalx4,3,5) cursor5.posy = smooth(var.finaly4,3,5) else var.leftpoint4 = 0 endif var.xpos4 = var.finalx4 var.ypos4 = var.finaly4 ppjoy4.analog0 = ensuremaprange(var.xpos4,0,screen.desktopwidth* var.coeff,-1,1) ppjoy4.analog1 = ensuremaprange(var.ypos4,0,screen.desktopheight* var.coeff,-1,1) if wiimote4.B or wiimote4.A or wiimote4.Up or wiimote4.down or wiimote4.Left or wiimote4.Right == true ppjoy4.digital0 = true else ppjoy4.digital0 = false endif